package com.service;

import com.mapper.UserMapper;
import com.entity.UserInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.stereotype.Service;

import java.util.List;

import javax.annotation.Resource;

@Service
public class UserService {
	@Resource
	private UserMapper userMapper;
	public UserInfo selectUserLogin(UserInfo userInfo) {
		System.out.println("service login ִ >>>>>>>>>>>>>>> ");
		return userMapper.userLogin(userInfo);
	}

	public boolean userRegister(UserInfo userinfo) {
		UserInfo u = this.userMapper.selectOneUser(userinfo.getName());
		if (u != null) {// �û����Ѿ�����
			return false;
		}
		return this.userMapper.userRegister(userinfo);
	}
	//�޸��û�
	public Integer updateUser(UserInfo user) {
		return this.userMapper.updateUser(user);
	}
	//�����û�id��ѯһ���û�
	public UserInfo selectUserById(Integer id) {
		return this.userMapper.selectOneUserByID(id);
	}

	public Integer deleteUser(Integer id) {
		return this.userMapper.deleteUserByid(id);
	}
	// ��ѯ�����û�
	public PageInfo<UserInfo> selectAllUsers(Integer index, Integer size,String name) {

		PageHelper.startPage(index, size);//PageHelper ���Է�ҳ���
		List<UserInfo> users = this.userMapper.selectAllUser(name);//��ѯ���
		PageInfo<UserInfo> info = new PageInfo<UserInfo>(users); //PageInfo ���Է�ҳ���
		
		System.out.println("totol=======" + info.getTotal());
		System.out.println("EndRow=======" + info.getEndRow());
		/*System.out.println("FirstPage=======" + info.getFirstPage());
		System.out.println("LastPage=======" + info.getLastPage());*/
		System.out.println("NavigatePages=======" + info.getNavigatePages());
		System.out.println("NavigatepageNums=======" + info.getNavigatepageNums());
		System.out.println("PageSize=======" + info.getPageSize());
		System.out.println("Size=======" + info.getSize());
		System.out.println("PrePage=======" + info.getPrePage());
		System.out.println("StartRow=======" + info.getStartRow());
		System.out.println("Pages=======" + info.getPages());
		System.out.println("NextPage=======" + info.getNextPage());
		System.out.println("List=======" + info.getList());
	/*	System.out.println("LastPage=======" + info.getLastPage());
		System.out.println("FirstPage=======" + info.getFirstPage());*/
		System.out.println("isIsFirstPage()=======" + info.isIsFirstPage());
		System.out.println("isHasNextPage()=======" + info.isHasNextPage());
		System.out.println("isHasPreviousPage()=======" + info.isHasPreviousPage());
		System.out.println("PageNum()=======" + info.getPageNum());
		return info;
	}
}
